#include <config.h>
#include <encoding_manager.h>
#include <string.h>

static int Utf16leisSupported(unsigned char *pucFileName)
{
	const char aStrUtf16leHead[] = {0xFF, 0xFE, 0};

	if(strncmp(aStrUtf16leHead, (const char *)pucFileName, 2) == 0)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}

static int Utf16leGetCodeFrmBuffer(unsigned char *pucBufStart, unsigned char *pucBufEnd, unsigned int *pdwCode)
{
	if(pucBufStart + 1 < pucBufEnd)
	{
		*pdwCode = (((unsigned int)pucBufStart[1])<<8) + pucBufStart[0];
		return 2;
	}
	else
	{
		return 0;
	}
}


static T_EncodingOpr g_tUtf16leEncodingOpr = {
	.name = "utf16le",
	.iHeadLen    = 2,
	.isSupported = Utf16leisSupported,
	.GetCodeFrmBuffer = Utf16leGetCodeFrmBuffer,
};

int Utf16leRegister(void)
{
	AddFontOprForEncoding(&g_tUtf16leEncodingOpr, GetFontOpr("freetype"));
	AddFontOprForEncoding(&g_tUtf16leEncodingOpr, GetFontOpr("ascii"));
	return RegisterEncodingOpr(&g_tUtf16leEncodingOpr);
}


